package com.auemall.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.auemall.constant.ApplicationConstant;
import com.auemall.service.OrderService;
import com.auemall.utils.EUDataGridResult;
import com.auemall.vo.BaseRespVO;
import com.auemall.vo.OrderDetailRespVO;
import com.auemall.vo.OrderVO;

/**
 * 
 * @ClassName: OrderController 
 * @Description: TODO (订单管理Controller)
 * @author WangChao
 * @date 2017年5月18日 下午4:15:37
 */
@Controller
public class OrderController {
    
    private Logger logger = Logger.getLogger(OrderController.class);

    @Autowired
    private OrderService orderService;
    
    /**
     * 
     * @Title: selectOrderList 
     * @Description: TODO(查询订单列表)
     * @param req
     * @param page
     * @param rows
     * @return EUDataGridResult  
     * @author WangChao
     */
    @RequestMapping("/order/v1/orderlist")
    @ResponseBody
    public EUDataGridResult selectOrderList(@RequestBody OrderVO req,Integer page, Integer rows) {
        EUDataGridResult result;
        try{
            result = orderService.selectOrderList(req, page, rows);
        }catch(Exception e){
            result = new EUDataGridResult();
            result.setResult(ApplicationConstant.RESULT_FALTURE);
            result.setMsg("order/v1/orderlist 查询订单列表失败："+e.getMessage());
            logger.error(result.getMsg());
        }
        return result;
    }
    
    /**
     * 
     * @Title: addOrder 
     * @Description: TODO(新增订单信息)
     * @param req
     * @return BaseRespVO  
     * @author WangChao
     */
    @RequestMapping(value="/order/v1/addorder", method=RequestMethod.POST)
    @ResponseBody
    private BaseRespVO addOrder(OrderVO req) {
        BaseRespVO respVO;
        try{
            respVO = orderService.addOrder(req);
        }catch(Exception e){
            respVO = new BaseRespVO();
            respVO.setResult(ApplicationConstant.RESULT_FALTURE);
            respVO.setMsg("添加订单信息异常（/order/v1/addorder）："+e.getMessage());
            logger.error(respVO.getMsg());
        }
        return respVO;
    }
    
    /**
     * 
     * @Title: updateOrder 
     * @Description: TODO(修改订单信息)
     * @param req
     * @return BaseRespVO  
     * @author WangChao
     */
    @RequestMapping(value="/order/v1/updateorder", method=RequestMethod.POST)
    @ResponseBody
    private BaseRespVO updateOrder(OrderVO req) {
        BaseRespVO respVO;
        try{
            respVO = orderService.updateOrder(req);
        }catch(Exception e){
            respVO = new BaseRespVO();
            respVO.setResult(ApplicationConstant.RESULT_FALTURE);
            respVO.setMsg("修改订单信息异常（/order/v1/updateorder）："+e.getMessage());
            logger.error(respVO.getMsg());
        }
        return respVO;
    }
    
    /**
     * 
     * @Title: deleteOrder 
     * @Description: TODO(删除订单信息)
     * @param req
     * @return BaseRespVO  
     * @author WangChao
     */
    @RequestMapping("/order/v1/deleteorder")
    @ResponseBody
    private BaseRespVO deleteOrder(@RequestBody OrderVO req) {
        BaseRespVO respVO;
        try{
            respVO = orderService.deleteOrder(req);
        }catch(Exception e){
            respVO = new BaseRespVO();
            respVO.setResult(ApplicationConstant.RESULT_FALTURE);
            respVO.setMsg("删除订单信息异常（/order/v1/deleteorder）："+e.getMessage());
            logger.error(respVO.getMsg());
        }
        return respVO;
    }
    
    /**
     * 
     * @Title: selectOrderDetail 
     * @Description: TODO(查询订单详情)
     * @param req
     * @return OrderDetailRespVO  
     * @author WangChao
     */
    @RequestMapping("/order/v1/orderdetail")
    @ResponseBody
    private OrderDetailRespVO selectOrderDetail(@RequestBody OrderVO req) {
        OrderDetailRespVO respVO;
        try{
            respVO = orderService.selectOrderDetail(req);
        }catch(Exception e){
            respVO = new OrderDetailRespVO();
            respVO.setResult(ApplicationConstant.RESULT_FALTURE);
            respVO.setMsg("查询订单详情异常（/order/v1/orderdetail）："+e.getMessage());
            logger.error(respVO.getMsg());
        }
        return respVO;
    }
    
    /**
     * 
     * @Title: deleteOrderDetail 
     * @Description: TODO(删除订单详情)
     * @param id
     * @return BaseRespVO  
     * @author WangChao
     */
    @RequestMapping("/order/v1/deleteorderdetail")
    @ResponseBody
    private BaseRespVO deleteOrderDetail(@RequestBody String id) {
        BaseRespVO respVO;
        try{
            respVO = orderService.deleteOrderDetail(id);
        }catch(Exception e){
            respVO = new BaseRespVO();
            respVO.setResult(ApplicationConstant.RESULT_FALTURE);
            respVO.setMsg("删除订单详情信息异常（/order/v1/deleteorderdetail）："+e.getMessage());
            logger.error(respVO.getMsg());
        }
        return respVO;
    }

}
